<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="900px" append-to-body custom-class="import-dialog">
      <div class="dialog-content" v-loading="loading">
        <div class="content-item" v-for="(item, index) in list" :key="index">
          <el-descriptions :column="4" :colon="false">
            <el-descriptions-item>{{ item.processName }}</el-descriptions-item>
            <el-descriptions-item label="状态:">
              <dict-tag :options="dict.type.facilities_state" :value="item.facilitiesState"
                        v-if="item.facilitiesState"
              />
              <span v-else>--</span>
            </el-descriptions-item>
            <el-descriptions-item label="上传人:">{{ item.uploadUser }}</el-descriptions-item>
            <el-descriptions-item label="上传时间:">{{ item.createTime }}</el-descriptions-item>
          </el-descriptions>
          <div class="content-item-img">
            <div class="content-item-img-item" v-for="(pic, index) in picStrToList(item.pictureSet)" :key="index">
              <el-image
                :src="pic"
                :preview-src-list="picStrToList(item.pictureSet)"
                lazy
              >
              </el-image>
            </div>
          </div>
          <el-descriptions :column="1" :colon="false">
            <el-descriptions-item label="备注:">{{ item.remark? item.remark : '--' }}</el-descriptions-item>
          </el-descriptions>

        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getHousePictureInfo } from '@/api/houseManagement/housePicture'

export default {
  name: 'Detail',
  dicts: ['facilities_state'],
  components: {},
  props: {
    title: {
      default: '详情'
    },
    value: {
      default: false
    },
    data: {
      default: undefined
    }
  },
  data() {
    return {
      // 表单
      form: {},
      rules: {},
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: []
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    //图片字符串转数组
    picStrToList() {
      return (value)=>{
        console.log('picStrToList',value)
        return value ? Array.isArray(value) ? value : value.split(',') : []
      }

    }
  },
  watch: {
    value: {
      handler(newVal, oldVal) {
        if (newVal) {
          this.init()
        }
      },
      immediate: true
    }
  },
  methods: {
    init() {
      this.reset()
      this.getDetail()
    },
    reset() {
      this.form = {}
      this.resetForm('form')

    },
    // 获取详情
    getDetail() {
      this.loading = true
      this.list = []
      getHousePictureInfo({ packetIdentification: this.data.packetIdentification }).then(response => {
        console.log(response)
        this.list = response.data
        this.$nextTick(() => {
          this.loading = false
        })
      }).catch(error => {
        console.log(error)
        this.list = []
        this.loading = false
      })
    },
    // 取消
    cancel() {
      this.reset()
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/dialog";
.content-item{
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
  &:last-child{
    margin-bottom: 0;
    border-bottom: none;
  }
  .content-item-img{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    grid-gap: 10px;
    padding: 10px 0;
    .content-item-img-item{
      ::v-deep.el-image{
        width: 100%;
        height: 100%;
        border-radius: 5px;
        cursor: pointer;
        border: 1px solid #eee;
      }
    }
  }
}
</style>
